var FZFVIDEO =
    '<div id="fz-videoBox">' +
    '<div class="fz-loading">' +
    '<div id="bfBtn" style="visibility:hidden;opacity:0;">' +
    '<div class="spinner">' +
    '<div class="spinner-container container1">'+
    '<div class="circle1"></div>'+
    '<div class="circle2"></div>'+
    '<div class="circle3"></div>'+
    '<div class="circle4"></div>'+
    '</div>'+
    '<div class="spinner-container container2">'+
    '<div class="circle1"></div>'+
    '<div class="circle2"></div>'+
    '<div class="circle3"></div>'+
    '<div class="circle4"></div>'+
    '</div>'+
    '<div class="spinner-container container3">'+
    '<div class="circle1"></div>'+
    '<div class="circle2"></div>'+
    '<div class="circle3"></div>'+
    '<div class="circle4"></div>'+
    '</div>'+
    '</div>' +
    '</div>' +
    '</div>' +
    '<div id="videoWrapper">' +
    '<canvas style="width:  100%;height:  100%;"></canvas>' +
    '<video src="" poster="" id="fz-videoAct" x-webkit-airplay="allow" x5-playsinline="" webkit-playsinline playsinline controlsList="nodownload" controls></video>' +
    '</div>' +
    '</div>';

function createVideo(dn, obj) {
    //节点池
    var fzPools = {}

    //点击后停止现实缓冲动画标记
    var hcqStop = 0;

    //标记播放过程中点击video容器后长时间无操作状态
    var flag = 0;

    //获取节点
    this.D = function (dms) {
        var dom_ = document.getElementById(dms);
        return dom_;
    }

    //设置播放器地址
    this.setUrl = function (url) {
        this.D('fz-videoAct').src = url;
    }

    //设置poster
    this.setPoster = function (poster) {
        this.D('fz-videoAct').poster = poster;
    }


    //初始化播放器属性
    this.init = function () {
        //设置播放器地址
        this.setUrl(obj.url);
        //设置poster
        this.setPoster(obj.poster);

        //判断是否自动播放
//        console.log(obj.autoplay,obj.currentTime);
        if (obj.autoplay) {
            this.videoDOM.play();
//            this.videoDOM.onplay=function () {
//                var that=this;
//                var Interval=window.setInterval(currentTimeTask, 500);
//                function currentTimeTask() {
//                    if (that.currentTime > 0) {
//                        that.controls = "controls";
//                        clearInterval(Interval);
//                    }
//                }
//
//            }
        } else {
            this.videoDOM.autoplay = false;
            this.videoDOM.currentTime = (obj.currentTime > 0) ? obj.currentTime : 0;
            console.log(obj.currentTime,this.videoDOM.currentTime);
        }

        //缓冲暂停事件
        fzPools.VIDEO_DOM.onwaiting = function () {
            openLoading("on");
        }

        //缓冲完毕继续播放事件
        fzPools.VIDEO_DOM.onplaying = function () {
            openLoading("off");
        }

        //打开或关闭加载
        function openLoading(states) {
            if (states == "on") {
                fzPools.bfBtn.style.visibility = "visible";
                fzPools.bfBtn.style.opacity = "1";
            } else {
                fzPools.bfBtn.style.visibility = "hidden";
                fzPools.bfBtn.style.opacity = "0";
            }
        }

        //播放结束
        fzPools.VIDEO_DOM.onended=function(){
            this.pause();
            $('#currentTimeBox,#fullscreen,#playOrStop').hide();
            $("#replay_wrapper").show();
        }



    }

    //创建播放器
    this.createDom = function () {
        if (this.D("fz-videoBox") == null) {
            this.D(dn).innerHTML = FZFVIDEO;
            this.videoDOM = this.D("fz-videoAct");
            saveDom();
            this.init();
        } else {
            console.log("播放器节点已存在");
            return;
        }
    }

    //销毁实例
    this.overVideo = function () {
        var ovDom = document.getElementById(dn);
        var childs = ovDom.childNodes;
        var length = childs.length;
        for (var i = 0; i < length; i++) {
            ovDom.removeChild(childs[0]);
        }
        FZ_VIDEO = '';
        $('#fz-videoBox').remove();
    }
    /*--------------------------------------方法-------------------------------------*/
    //将节点存入节点池
    function saveDom() {
        fzPools.VIDEO_DOM = document.getElementById("fz-videoAct");
        fzPools.bfBtn = document.getElementById("bfBtn");
        fzPools.sptxt = document.getElementById("sptxt");
        fzPools.replay = document.getElementById("replay");
        fzPools.items = document.getElementsByClassName("item_Poster");
        fzPools.bs1 = document.getElementById("bs1");
        fzPools.bs2 = document.getElementById("bs2");
        fzPools.bs3 = document.getElementById("bs3");
        fzPools.bs4 = document.getElementById("bs4");
    }


    //打开或关闭加载
    function openLoading(states, msg) {
        if (states == "on") {
            fzPools.bfBtn.style.visibility = "visible";
            fzPools.bfBtn.style.opacity = "1";
            fzPools.sptxt.innerHTML = msg;
        } else {
            fzPools.bfBtn.style.visibility = "hidden";
            fzPools.bfBtn.style.opacity = "0";
            fzPools.sptxt.innerHTML = '';
        }
    }

    this.createDom();
}
